# GNU/Makefile for bzip2 - block-sorting file compressor
# Copyright (C):
# Makefile/script: 2010-2022 Antonio Diaz Diaz
# 2022 tansy
# bzip2:
# 1996-2010 Julian Seward <jseward@acm.org>
# 2019-2020 Federico Mena Quintero <federico@gnome.org>
# 2021 [Micah Snyder](https://gitlab.com/micahsnyder)
#
# This file was generated automatically by configure.
# Beware if you want to edit it.
#
# This Makefile is free software: you have unlimited permission
# to copy, distribute, and modify it.
#
pkgname = bzip2
pkgversion = 1.1.0
progname = bzip2
makefile = GNUMakefile
VPATH = .
prefix = /usr/local
exec_prefix = $(prefix)
bindir = $(exec_prefix)/bin
datarootdir = $(prefix)/share
infodir = $(datarootdir)/info
mandir = $(datarootdir)/man
CC = gcc
DEFINES = -DBZ_UNIX -D_FILE_OFFSET_BITS=64
WARNINGS = -Wno-unused-parameter
CFLAGS = -g -Wall -W -O2 $(DEFINES) $(WARNINGS)
LDFLAGS = 

DISTNAME = $(pkgname)-$(pkgversion)
INSTALL = install
INSTALL_PROGRAM = $(INSTALL) -m 755
INSTALL_DATA = $(INSTALL) -m 644
INSTALL_DIR = $(INSTALL) -d -m 755
SHELL = /bin/sh
CAN_RUN_INSTALLINFO = $(SHELL) -c "install-info --version" > /dev/null 2>&1

objs =  blocksort.o  \
        bzip2.o      \
        bzlib.o      \
        compress.o   \
        crctable.o   \
        decompress.o \
        huffman.o    \
        randtable.o  \

.PHONY : all install install-bin install-info install-man \
         install-strip install-compress install-strip-compress \
         install-bin-strip install-info-compress install-man-compress \
         uninstall uninstall-bin uninstall-info uninstall-man \
         doc info man check dist clean distclean

all : $(progname)

$(progname) : $(objs)
	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(objs)

%.o : %.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

#$(objs) : $(makefile)-$(pkgname)
$(objs) :
blocksort.o : blocksort.c bzlib_private.h bzlib.h
bzip2.o: bzip2.c bzlib.h
bzlib.o : bzlib.c bzlib_private.h bzlib.h bz_version.h
compress.o : compress.c bzlib_private.h bzlib.h
crctable.o : crctable.c bzlib_private.h bzlib.h
decompress.o : decompress.c bzlib_private.h bzlib.h
huffman.o : huffman.c bzlib_private.h bzlib.h
randtable.o : randtable.c bzlib_private.h bzlib.h

doc : man

info : $(VPATH)/doc/$(pkgname).info

$(VPATH)/doc/$(pkgname).info : $(VPATH)/doc/$(pkgname).texi
	cd $(VPATH)/doc && makeinfo $(pkgname).texi

man : $(VPATH)/doc/man/bzdiff.1 $(VPATH)/doc/man/bzgrep.1 \
    $(VPATH)/doc/man/bzip2.1 $(VPATH)/doc/man/bzmore.1

$(VPATH)/doc/man/bzip2.1 : $(progname)
	help2man -n 'reduces the size of files' -o $@ ./$(progname)

Makefile : $(VPATH)/configure $(VPATH)/$(makefile)-$(pkgname).in
	./config.status

check : all
	@$(VPATH)/test/check.sh $(VPATH)/testsuite $(pkgversion)

install : install-bin install-man
install-strip : install-bin-strip install-info install-man
install-compress : install-bin install-info-compress install-man-compress
install-strip-compress : install-bin-strip install-info-compress install-man-compress

install-bin : all
	if [ ! -d "$(DESTDIR)$(bindir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(bindir)" ; fi
	$(INSTALL_PROGRAM) ./$(progname) "$(DESTDIR)$(bindir)/$(progname)"

install-bin-strip : all
	$(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' install-bin

install-info :
	if [ ! -d "$(DESTDIR)$(infodir)" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(infodir)" ; fi
	-rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"*
	$(INSTALL_DATA) $(VPATH)/doc/$(pkgname).info "$(DESTDIR)$(infodir)/$(pkgname).info"
	-if $(CAN_RUN_INSTALLINFO) ; then \
	  install-info --info-dir="$(DESTDIR)$(infodir)" "$(DESTDIR)$(infodir)/$(pkgname).info" ; \
	fi

install-info-compress : install-info
	bzip2 -v -9 "$(DESTDIR)$(infodir)/$(pkgname).info"

install-man :
	if [ ! -d "$(DESTDIR)$(mandir)/man1" ] ; then $(INSTALL_DIR) "$(DESTDIR)$(mandir)/man1" ; fi
	-rm -f "$(DESTDIR)$(mandir)/man1/bzdiff.1"*
	$(INSTALL_DATA) $(VPATH)/doc/man/bzdiff.1 "$(DESTDIR)$(mandir)/man1/bzdiff.1"
	-rm -f "$(DESTDIR)$(mandir)/man1/bzgrep.1"*
	$(INSTALL_DATA) $(VPATH)/doc/man/bzgrep.1 "$(DESTDIR)$(mandir)/man1/bzgrep.1"
	-rm -f "$(DESTDIR)$(mandir)/man1/bzip2.1"*
	$(INSTALL_DATA) $(VPATH)/doc/man/bzip2.1 "$(DESTDIR)$(mandir)/man1/bzip2.1"
	-rm -f "$(DESTDIR)$(mandir)/man1/bzmore.1"*
	$(INSTALL_DATA) $(VPATH)/doc/man/bzmore.1 "$(DESTDIR)$(mandir)/man1/bzmore.1"

install-man-compress : install-man
	bzip2 -v -9 "$(DESTDIR)$(mandir)/man1/bzdiff.1"
	bzip2 -v -9 "$(DESTDIR)$(mandir)/man1/bzgrep.1"
	bzip2 -v -9 "$(DESTDIR)$(mandir)/man1/bzip2.1"
	bzip2 -v -9 "$(DESTDIR)$(mandir)/man1/bzmore.1"

uninstall : uninstall-man uninstall-info uninstall-bin

uninstall-bin :
	-rm -f "$(DESTDIR)$(bindir)/$(progname)"

uninstall-info :
	-if $(CAN_RUN_INSTALLINFO) ; then \
	  install-info --info-dir="$(DESTDIR)$(infodir)" --remove "$(DESTDIR)$(infodir)/$(pkgname).info" ; \
	fi
	-rm -f "$(DESTDIR)$(infodir)/$(pkgname).info"*

uninstall-man :
	-rm -f "$(DESTDIR)$(mandir)/man1/bzdiff.1"*
	-rm -f "$(DESTDIR)$(mandir)/man1/bzgrep.1"*
	-rm -f "$(DESTDIR)$(mandir)/man1/bzip2.1"*
	-rm -f "$(DESTDIR)$(mandir)/man1/bzmore.1"*

dist : doc
	ln -sf $(VPATH) $(DISTNAME)
	tar -Hustar --owner=root --group=root -cvf $(DISTNAME).tar \
	  $(DISTNAME)/AUTHORS \
	  $(DISTNAME)/COPYING \
	  $(DISTNAME)/ChangeLog \
	  $(DISTNAME)/INSTALL \
	  $(DISTNAME)/$(makefile)-$(pkgname).in \
	  $(DISTNAME)/NEWS \
	  $(DISTNAME)/README \
	  $(DISTNAME)/configure-$(pkgname) \
	  $(DISTNAME)/doc/man/bzdiff.1 \
	  $(DISTNAME)/doc/man/bzgrep.1 \
	  $(DISTNAME)/doc/man/bzip2.1 \
	  $(DISTNAME)/doc/man/bzmore.1 \
	  $(DISTNAME)/*.h \
	  $(DISTNAME)/*.c \
	  $(DISTNAME)/test/runtest.py \
	  $(DISTNAME)/test/sample1.bz2 \
	  $(DISTNAME)/test/sample2.bz2 \
	  $(DISTNAME)/test/sample3.bz2 \
	  $(DISTNAME)/test/sample1.ref \
	  $(DISTNAME)/test/sample2.ref \
	  $(DISTNAME)/test/sample3.ref \
	rm -f $(DISTNAME)
	bzip2 -v -9 $(DISTNAME).tar

clean :
	-rm -f $(progname) $(objs)

distclean : clean
	-rm -f $(makefile)-$(pkgname) config.status *.tar *.tar.bz2
